package farmers.stream;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class A003_map工具类 {


    @Test
    public void mapToList(){

//        https://blog.csdn.net/Hatsune_Miku_/article/details/73435627?spm=1001.2101.3001.6650.2&depth_1-utm_relevant_index=5
        Map<String, String> map = new HashMap<>();

// Convert all Map keys to a List
        List<String> result = new ArrayList(map.keySet());

// Convert all Map values to a List
        List<String> result2 = new ArrayList(map.values());

// Java 8, Convert all Map keys to a List
        List<String> result3 = map.keySet().stream().collect(Collectors.toList());

// Java 8, Convert all Map values  to a List
        List<String> result4 = map.values().stream().collect(Collectors.toList());

// Java 8, seem a bit long, but you can enjoy the Stream features like filter and etc.
        List<String> result5 = map.values().stream().filter(x -> !"apple".equalsIgnoreCase(x)).collect(Collectors.toList());

    }

//    @Test
//    public void lsitToString(){
//
//    }
//
//
//    @Test
//    public void mapToString(){
//
//    }

}
